package util.designpattern.delegate;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class DispatcherServlet extends HttpServlet {

    private void doDispatch(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String uri = request.getRequestURI();
        String mid = request.getParameter("mid");
        if("getMemberBuId".equals(uri)){
            new MemberController().getMemberById(mid);
        }else if("logout".equals(uri)){
            new SystemController().logout();
        }else {
            response.getWriter().write("404 NOT Found!");
        }
    }

    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException {
        try {
            doDispatch(request,response);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
